package com.xdb.sqlparser.dialect.mysql.ast;

import com.xdb.sqlparser.ast.SQLName;
import com.xdb.sqlparser.ast.statement.SQLForeignKeyImpl;
import com.xdb.sqlparser.dialect.mysql.visitor.MySqlASTVisitor;
import com.xdb.sqlparser.visitor.SQLAstVisitor;

public class MysqlForeignKey extends SQLForeignKeyImpl {

	private SQLName indexName;

	private boolean hasConstraint;

	private Match referenceMatch;

	private On referenceOn;

	private Option referenceOption;

	public SQLName getIndexName() {
		return indexName;
	}

	public void setIndexName(SQLName indexName) {
		this.indexName = indexName;
	}

	public boolean isHasConstraint() {
		return hasConstraint;
	}

	public void setHasConstraint(boolean hasConstraint) {
		this.hasConstraint = hasConstraint;
	}

	@Override
	protected void accept0(SQLAstVisitor visitor) {
		if (visitor instanceof MySqlASTVisitor) {
			accept0((MySqlASTVisitor) visitor);
		}
	}

	protected void accept0(MySqlASTVisitor visitor) {
		if (visitor.visit(this)) {
			acceptChild(visitor, this.getName());
			acceptChild(visitor, this.getReferencedTableName());
			acceptChild(visitor, this.getReferencingColumns());
			acceptChild(visitor, this.getReferencedColumns());

			acceptChild(visitor, indexName);
		}
		visitor.endVisit(this);
	}

	public Match getReferenceMatch() {
		return referenceMatch;
	}

	public void setReferenceMatch(Match referenceMatch) {
		this.referenceMatch = referenceMatch;
	}

	public On getReferenceOn() {
		return referenceOn;
	}

	public void setReferenceOn(On referenceOn) {
		this.referenceOn = referenceOn;
	}

	public Option getReferenceOption() {
		return referenceOption;
	}

	public void setReferenceOption(Option referenceOption) {
		this.referenceOption = referenceOption;
	}

	public static enum Option {

		RESTRICT("RESTRICT"), CASCADE("CASCADE"), SET_NULL("SET NULL"), NO_ACTION("NO ACTION");

		private String text;

		Option(String text) {
			this.text = text;
		}

		public String getText() {
			return text;
		}

	}

	public static enum Match {
		FULL, PARTIAL, SIMPLE;
	}

	public static enum On {
		DELETE, UPDATE;
	}
}
